o "Guess a number game starts!"



# Enter your real name in pinyin and student ID below

echo "Name: caozhengho, ID: 24055060153"





# Generate a random number NUM1 using RANDOM

NUM1=$(( RANDOM % 100 + 1 ))



START=1

MAX=7



# Use while loop to judge the size of start and max

while [ $START -le $MAX ]; do

  

  # Read the number entered by the user from the terminal and assign it to the variable NUM2

  read -p "$START/$MAX: Please input a number (1-100): " NUM2

  

  # Logic for judging NUM1 and NUM2 and outputting prompt information

  if [ $NUM2 -eq $NUM1 ]; then

    echo "You guessed it right!"

    exit 0

  elif [ $NUM2 -gt $NUM1 ]; then

    echo "The number you entered is too big."

  else

    echo "The number you entered is too small."

  fi

  

  START=$(( START + 1 ))

done



# If you still haven't guessed correctly after the loop ends, execute the prompt that you lost

echo "You lost!"

echo "The correct number is: $NUM1"

exit 1
